//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;
using OpenLS.Spreadsheet.Formats.Biff.Records;

namespace OpenLS.Spreadsheet.Formats.Biff
{
#if DEBUG
    public 
#endif
    class BiffReaderContext
    {
        readonly List<XFRecord> _xfRecords = new List<XFRecord>();
        internal List<XFRecord> XFRecords { get { return _xfRecords; } }
        private BinaryReader _reader;
        private readonly Queue<BoundSheetRecord> _boundSheets = new Queue<BoundSheetRecord>();

        public BiffReaderContext(BinaryReader reader)
        {
            this._reader = reader;
        }

        public Stream BaseStream
        {
            get { return _reader.BaseStream; }
        }

        public BinaryReader Reader
        {
            get {
                return _reader;
            }
            set {
                _reader = value;
            }
        }

        internal Queue<BoundSheetRecord> Boundsheets
        {
            get { return _boundSheets; }
        }

        private BiffRecord _previousRecord;

        public BiffRecord PreviousRecord
        {
            get { return _previousRecord; }
            set
            {
                Contract.Requires(value != null);
                _previousRecord = value;
            }
        }

        internal SupBookRecord PreviousSupBook { get; set; }

        public ushort ReadUInt16()
        {
            
            return this._reader.ReadUInt16();
        }

        public int ReadInt32()
        {
            return _reader.ReadInt32();
        }

        public sbyte ReadSByte()
        {
            return _reader.ReadSByte();
        }

        public byte ReadByte()
        {
            return _reader.ReadByte();
        }

        public uint ReadUInt32()
        {
            return _reader.ReadUInt32();
        }

        public double ReadDouble()
        {
            return _reader.ReadDouble();
        }

        public short ReadInt16()
        {
            return _reader.ReadInt16();
        }

        public byte[] ReadBytes(int i)
        {
            return _reader.ReadBytes(i);
        }

        public ushort PeekUInt16()
        {
            var position = _reader.BaseStream.Position;
            var result = ReadUInt16();
            _reader.BaseStream.Position = position;
            return result;
        }
        internal FtType PeekFtType()
        {
            return (FtType) PeekUInt16();
        }

    }
}